﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Collections;

namespace LinqToPowershell
{
    [Cmdlet("New", "Query")]
    public class NewQueryCmdlet : PSCmdlet
    {        
        [Parameter(Mandatory = true, Position = 0)]
        public IQueryable Input { get; set; }

        //[Parameter(ParameterSetName = "Eager", Mandatory = true)]
        //public IEnumerable EagerInput { get; set; }                

        protected override void ProcessRecord()
        {
            //IEnumerable Input;
            //if (ParameterSetName == "Lazy")
            //    Input = LazyInput;
            //else                
            //    Input = EagerInput;

            var typeArgs = Input.GetTypeArgs();
            if (typeArgs == null)
            {
                WriteObject(new QueryableWrapper(Input));
            }
            else
            {
                var generic = GenericHelper.Create<QueryableWrapper>(typeArgs, Input);
                WriteObject(generic);
            }
        }
    }
}
